package com.example.teamtribe.main.mine;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.teamtribe.R;
import com.example.teamtribe.base.BaseFragment;
import com.example.teamtribe.database.User;
import com.example.teamtribe.main.club.activity.ActivityActivity;
import com.example.teamtribe.main.club.moment.MomentActivity;
import com.example.teamtribe.main.mine.club.ClubActivity;
import com.example.teamtribe.main.mine.info.MyInfoActivity;
import com.example.teamtribe.main.mine.setting.SettingActivity;
import com.example.teamtribe.main.mine.sign.SignActivity;
import com.example.teamtribe.utils.Utility;

public class MineFragment extends BaseFragment implements View.OnClickListener{

    private ImageView ivHead;
    private TextView tvNickname;

    @Override
    protected int setContentView() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void onCreateView(View view) {
        tvNickname = view.findViewById(R.id.tv_nickname);
        ivHead = view.findViewById(R.id.iv_head);
        view.findViewById(R.id.ll_myInformation).setOnClickListener(this);
        view.findViewById(R.id.ll_myMoments).setOnClickListener(this);
        view.findViewById(R.id.ll_mine_setting).setOnClickListener(this);
        view.findViewById(R.id.iv_sign).setOnClickListener(this);
        view.findViewById(R.id.ll_myTeams).setOnClickListener(this);
        view.findViewById(R.id.ll_myActivities).setOnClickListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        setInfo();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_myInformation:
                startActivity(new Intent(getActivity(), MyInfoActivity.class));
                break;

            case R.id.ll_myMoments:
                Intent intent = new Intent(getContext(), MomentActivity.class);
                intent.putExtra("mode", MomentActivity.MODE_USER);
                intent.putExtra("id", Utility.getUser().getRealId());
                startActivity(intent);
                break;

            case R.id.ll_mine_setting:
                startActivity(new Intent(getActivity(), SettingActivity.class));
                break;

            case R.id.iv_sign:
                startActivity(new Intent(getActivity(), SignActivity.class));
                break;

            case R.id.ll_myActivities:
                startActivity(new Intent(getActivity(), ActivityActivity.class));
                break;

            case R.id.ll_myTeams:
                startActivity(new Intent(getActivity(), ClubActivity.class));
                break;

            default:
                break;
        }
    }

    private void setInfo() {
        User user = Utility.getUser();
        Glide.with(this).load(Utility.getUri(user.getPortrait())).into(ivHead);
        tvNickname.setText(user.getNickname());
    }
}